<?php

use Illuminate\Database\Seeder;

use App\Models\Goods;
use App\Repositories\CategoryRepository;
use App\Models\Brand;
use App\Models\Category;
class FixGoddsSearchKeywords extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        $categoryService = new CategoryRepository();

        $goods_ids = Goods::lists('goods_id');


        foreach ($goods_ids as $goods_id){

            $goods = Goods::find($goods_id);

            $keywordsStr = $goods->keywords;

            $brand = Brand::find($goods->brand_id);

            if ($brand){
                $keywordsStr.=','.$brand->brand_name;
            }


            $category = Category::find($goods->cat_id);
            if ($category) $keywordsStr.=','.$category->cat_name.','.$category->keywords;

            $goods = Goods::find($goods_id);

            $goods->search_keywords = $keywordsStr;

            $goods->save();

            echo (PHP_EOL.'fixed:'.$goods->goods_id.PHP_EOL);

        }

    }
}
